package org.example.Day10.xiancheng;

import java.util.concurrent.*;

public class Test {
    public static void main(String[] args){
        ExecutorService pool = new ThreadPoolExecutor(
                3,//核⼼线程数有3个
                5,//最⼤线程数有5个。 临时线程数=最⼤线程数-核⼼线程数=5-3=2
                8,//临时线程存活的时间8秒。 意思是临时线程8秒没有任务执⾏，就会被销毁掉。
                TimeUnit.SECONDS,//时间单位（秒）
                new ArrayBlockingQueue<>(4),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.CallerRunsPolicy()
        );
        Runnable target = new MyRunnable();
        pool.execute(target);// 线程池会⾃动创建⼀个新线程，⾃动处理这个任务，⾃动执⾏的
        pool.execute(target);
        pool.execute(target);
        //下面4个任务在排队
        pool.execute(target);
        pool.execute(target);
        pool.execute(target);
        pool.execute(target);

        //下⾯2个任务，会被临时线程的创建时机了
        pool.execute(target);
        pool.execute(target);
        // 到了新任务的拒绝时机了！
        pool.execute(target);
    }
}
